package com.api.syh56.shengyunhui.controller;

import com.api.syh56.shengyunhui.common.CommonPage;
import com.api.syh56.shengyunhui.common.CommonResult;
import com.api.syh56.shengyunhui.entity.Slide;
import com.api.syh56.shengyunhui.service.AdminSlideService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 轮播图
 */
@RestController
@RequestMapping("slide")
public class SlideController {
    @Autowired
    private AdminSlideService adminSlideService;


    /**
     * 查看轮播图
     * @return
     */
    @GetMapping("show")
    public CommonResult<List<Slide>> show(){
        QueryWrapper<Slide> slideQueryWrapper = new QueryWrapper<>();
        slideQueryWrapper.lambda().eq(Slide::getIsEnable,1);
        List<Slide> slides = adminSlideService.list(slideQueryWrapper);
        return CommonResult.success(slides);
    }


    @GetMapping("selectBy")
    public CommonResult<CommonPage<Slide>> selectBy(@RequestParam String picName,
                                                    @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
                                                    @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum){
        Page<Slide> slides = adminSlideService.selectBy(picName,pageNum,pageSize);
        return CommonResult.success(CommonPage.restPage(slides));
    }
}

